home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / utilsys / rss14gmd.lha / RSys_1.4gmd / C / TextFormatter.c < prev    next >
C/C++ Source or Header  |  1996-05-04  |  9KB  |  366 lines

  1. /*
  2.    ***************************************************************************
  3.    *
  4.    * Datei:
  5.    *      RSysTextFormatter.c
  6.    *
  7.    * Inhalt:
  8.    *
  9.    *      --- Globale Routinen ---
  10.    *
  11.    *    int RSysFormatOutput ( WINDOW *wind , char *format );
  12.    *
  13.    *      --- Lokale  Routinen ---
  14.    *
  15.    *    static int BlankLeftCGadClicked ( void );
  16.    *    static int HandleFormatterIDCMP ( void );
  17.    *    static int NoFormatGadClicked ( void );
  18.    *    static int NoHeaderCGadClicked ( void );
  19.    *    static int OpenFormatterWindow ( void );
  20.    *    static int PostFixSGadClicked ( void );
  21.    *    static int PrefixSGadClicked ( void );
  22.    *    static int QuoteCGadClicked ( void );
  23.    *    static int UseGadClicked ( void );
  24.    *    static void preview ( void );
  25.    *
  26.    * Bemerkungen:
  27.    *      Formatierung der Ausgabelisten von RSys.
  28.    *
  29.    * Erstellungsdatum:
  30.    *      07-Jul-93     Rolf Böhme
  31.    *
  32.    * Änderungen:
  33.    *      07-Jul-93     Rolf Böhme        Erstellung
  34.    *
  35.    ***************************************************************************
  36.  */
  37.  
  38. #include "RSys.h"
  39. #include "protos.h"
  40.  
  41.  
  42. RSYS_fmt TFormat, TFormatDef =
  43.  
  44. {
  45.   FALSE, FALSE, FALSE, TRUE, "", "", "%s"
  46. };
  47.  
  48. static WINDOW *FormatterWnd = NULL;
  49. static GADGET *FormatterGList = NULL;
  50. static INTUIMESSAGE FormatterMsg;
  51. static GADGET *FormatterGadgets[Formatter_CNT];
  52. static UWORD FormatterLeft = 47;
  53. static UWORD FormatterTop = 52;
  54. static UWORD FormatterWidth = 610;
  55. static UWORD FormatterHeight = 74;
  56. static UBYTE FormatterWdt[100];    /*GMD */
  57.  
  58. static UWORD FormatterGTypes[] =
  59. {
  60.   STRING_KIND,
  61.   STRING_KIND,
  62.   CHECKBOX_KIND,
  63.   CHECKBOX_KIND,
  64.   CHECKBOX_KIND,
  65.   TEXT_KIND,
  66.   BUTTON_KIND,
  67.   BUTTON_KIND
  68. };
  69.  
  70. static int PrefixSGadClicked (void);
  71. static int PostFixSGadClicked (void);
  72. static int BlankLeftCGadClicked (void);
  73. static int QuoteCGadClicked (void);
  74. static int NoHeaderCGadClicked (void);
  75. static int UseGadClicked (void);
  76. static int NoFormatGadClicked (void);
  77.  
  78. static NEWGADGET FormatterNGad[] =
  79. {
  80.   14, 17, 211, 13, (UBYTE *) "Prefix", NULL, GD_PrefixSGad, PLACETEXT_ABOVE, NULL, (APTR) PrefixSGadClicked,
  81.   384, 17, 211, 13, (UBYTE *) "Postfix", NULL, GD_PostFixSGad, PLACETEXT_ABOVE, NULL, (APTR) PostFixSGadClicked,
  82.   14, 33, 26, 11, (UBYTE *) "Blanks between texts", NULL, GD_BlankLeftCGad, PLACETEXT_RIGHT, NULL, (APTR) BlankLeftCGadClicked,
  83.   234, 33, 26, 11, (UBYTE *) "Quote-in text", NULL, GD_QuoteCGad, PLACETEXT_RIGHT, NULL, (APTR) QuoteCGadClicked,
  84.   419, 33, 26, 11, (UBYTE *) "No header in file", NULL, GD_NoHeaderCGad, PLACETEXT_RIGHT, NULL, (APTR) NoHeaderCGadClicked,
  85.   233, 17, 143, 13, (UBYTE *) "Text to save", NULL, GD_TextTGad, PLACETEXT_ABOVE, NULL, NULL,
  86.   119, 53, 147, 13, (UBYTE *) "Use Format", NULL, GD_UseGad, PLACETEXT_IN, NULL, (APTR) UseGadClicked,
  87.   343, 53, 147, 13, (UBYTE *) "No Format", NULL, GD_NoFormatGad, PLACETEXT_IN, NULL, (APTR) NoFormatGadClicked
  88. };
  89.  
  90. static ULONG *FormatterGTags[] =
  91. {
  92.   (ULONG *) (GTST_MaxChars), (ULONG *) 100, (ULONG *) (TAG_DONE),
  93.   (ULONG *) (GTST_MaxChars), (ULONG *) 100, (ULONG *) (TAG_DONE),
  94.   (ULONG *) (TAG_DONE),
  95.   (ULONG *) (TAG_DONE),
  96.   (ULONG *) (TAG_DONE),
  97.   (ULONG *) (GTTX_Text), (ULONG *) "This is text", (ULONG *) (GTTX_Border), (ULONG *) TRUE, (ULONG *) (TAG_DONE),
  98.   (ULONG *) (TAG_DONE),
  99.   (ULONG *) (TAG_DONE)
  100. };
  101.  
  102. static int
  103. UseGadClicked (void)
  104. {
  105.   TFormat.f_noformat = FALSE;
  106.  
  107.   strncpy (TFormat.f_prefix, gadgetbuff (FormatterGadgets[GD_PrefixSGad - GD_PrefixSGad]), 100);
  108.   strncpy (TFormat.f_postfix, gadgetbuff (FormatterGadgets[GD_PostFixSGad - GD_PrefixSGad]), 100);
  109.  
  110.   sprintf (TFormat.f_format, "%s%s%s%s%s%s%s",
  111.        TFormat.f_prefix,
  112.        TFormat.f_blanks ? " " : "",
  113.        TFormat.f_quote ? "\"" : "",
  114.        "\%s",
  115.        TFormat.f_quote ? "\"" : "",
  116.        TFormat.f_blanks ? " " : "",
  117.        TFormat.f_postfix
  118.     );
  119.  
  120.   return (FALSE);
  121. }
  122.  
  123. static void
  124. preview (void)
  125. {
  126.   char text[MAXWRITESIZE];
  127.  
  128.   DPOS;
  129.  
  130.   sprintf (text, "%s%s%s%s%s",
  131.        TFormat.f_blanks ? " " : "",
  132.        TFormat.f_quote ? "\"" : "",
  133.        "This is text",
  134.        TFormat.f_quote ? "\"" : "",
  135.        TFormat.f_blanks ? " " : "");
  136.  
  137.   GT_SetGadgetAttrs (FormatterGadgets[GD_TextTGad - GD_PrefixSGad], FormatterWnd,
  138.              NULL,
  139.              GTTX_Text, text,
  140.              TAG_DONE);
  141.  
  142.   (void) UseGadClicked ();
  143.  
  144.   return;
  145. }
  146.  
  147. static int
  148. PrefixSGadClicked (void)
  149. {
  150.   DPOS;
  151.  
  152.   strncpy (TFormat.f_prefix, gadgetbuff (FormatterGadgets[GD_PrefixSGad - GD_PrefixSGad]), 100);
  153.  
  154.   preview ();
  155.  
  156.   return TRUE;
  157. }
  158.  
  159. static int
  160. PostFixSGadClicked (void)
  161. {
  162.   DPOS;
  163.  
  164.   strncpy (TFormat.f_postfix, gadgetbuff (FormatterGadgets[GD_PostFixSGad - GD_PrefixSGad]), 100);
  165.  
  166.   preview ();
  167.  
  168.   return TRUE;
  169. }
  170.  
  171. static int
  172. BlankLeftCGadClicked (void)
  173. {
  174.   DPOS;
  175.  
  176.   TFormat.f_blanks = (TFormat.f_blanks ? FALSE : TRUE);
  177.  
  178.   preview ();
  179.  
  180.   return TRUE;
  181. }
  182.  
  183. static int
  184. QuoteCGadClicked (void)
  185. {
  186.   DPOS;
  187.  
  188.   TFormat.f_quote = (TFormat.f_quote ? FALSE : TRUE);
  189.  
  190.   preview ();
  191.  
  192.   return TRUE;
  193. }
  194.  
  195. static int
  196. NoHeaderCGadClicked (void)
  197. {
  198.   DPOS;
  199.  
  200.   TFormat.f_noheader = (TFormat.f_noheader ? FALSE : TRUE);
  201.  
  202.   return TRUE;
  203. }
  204.  
  205. static int
  206. NoFormatGadClicked (void)
  207. {
  208.   DPOS;
  209.  
  210.   TFormat.f_noformat = TRUE;
  211.   TFormat.f_noheader = FALSE;
  212.  
  213.   return FALSE;
  214. }
  215.  
  216. static int
  217. OpenFormatterWindow (void)
  218. {
  219.   NEWGADGET ng;
  220.   GADGET *g;
  221.   UWORD lc, tc;
  222.   UWORD wleft = FormatterLeft, wtop = FormatterTop, ww, wh;
  223.   int gl[] =
  224.   {GD_PrefixSGad - GD_PrefixSGad,
  225.    GD_PostFixSGad - GD_PrefixSGad,
  226.    GD_TextTGad - GD_PrefixSGad};
  227.  
  228.   DPOS;
  229.  
  230.   AdjustWindowDimensions (Scr, FormatterLeft, FormatterTop, FormatterWidth, FormatterHeight,
  231.               &wleft, &wtop, &ww, &wh);
  232.  
  233.   if (!(g = CreateContext (&FormatterGList)))
  234.     return 1L;
  235.  
  236.   for (lc = 0, tc = 0; lc < Formatter_CNT; lc++)
  237.     {
  238.       CopyMem ((char *) &FormatterNGad[lc], (char *) &ng,
  239.            (long) sizeof (NEWGADGET));
  240.  
  241.       ng.ng_VisualInfo = VisualInfo;
  242.       ng.ng_TextAttr = Font;
  243.       ng.ng_LeftEdge = OffX + ComputeX (ng.ng_LeftEdge);
  244.       ng.ng_TopEdge = OffY + ComputeY (ng.ng_TopEdge);
  245.       ng.ng_Width = ComputeX (ng.ng_Width);
  246.       ng.ng_Height = ComputeY (ng.ng_Height);
  247.  
  248.       FormatterGadgets[lc] = g = CreateGadgetA ((ULONG) FormatterGTypes[lc], g, &ng, (TAGITEM *) & FormatterGTags[tc]);
  249.  
  250.       makelabelvisible (FormatterGadgets[lc]);
  251.  
  252.       while (FormatterGTags[tc])
  253.     tc += 2;
  254.       tc++;
  255.  
  256.       if (NOT g)
  257.     return 2L;
  258.     }
  259.  
  260.   strcpy (FormatterWdt, get_vers (" - Output Formatter"));    /*GMD */
  261.  
  262.   if (!(FormatterWnd = OpenWindowTags (NULL,
  263.                        WA_Left, wleft,
  264.                        WA_Top, wtop,
  265.                        WA_Width, ww,
  266.                        WA_Height, wh,
  267.                      WA_IDCMP, STRINGIDCMP | CHECKBOXIDCMP |
  268.                    TEXTIDCMP | BUTTONIDCMP | IDCMP_CLOSEWINDOW |
  269.                      IDCMP_REFRESHWINDOW | IDCMP_VANILLAKEY,
  270.                  WA_Flags, WFLG_DRAGBAR | WFLG_DEPTHGADGET |
  271.                      WFLG_CLOSEGADGET | WFLG_SMART_REFRESH |
  272.                        WFLG_ACTIVATE | WFLG_RMBTRAP,
  273.                        WA_Title, FormatterWdt,
  274.                        WA_PubScreenFallBack, TRUE,
  275.                        WA_PubScreen, Scr,
  276.                        TAG_DONE)))
  277.     return 4L;
  278.  
  279.   RefreshRastPort (FormatterWnd, FormatterGadgets, gl, 3, FALSE, FormatterGList);
  280.  
  281.   return NULL;
  282. }
  283.  
  284. static int
  285. HandleFormatterIDCMP (void)
  286. {
  287.   INTUIMESSAGE *m;
  288.   int (*func) (void), ID;
  289.   BOOL running = TRUE;
  290.  
  291.   DPOS;
  292.  
  293.   while (m = GT_GetIMsg (FormatterWnd->UserPort))
  294.     {
  295.       CopyMem ((char *) m, (char *) &FormatterMsg,
  296.            (long) sizeof (INTUIMESSAGE));
  297.  
  298.       GT_ReplyIMsg (m);
  299.  
  300.       switch (FormatterMsg.Class)
  301.     {
  302.     case IDCMP_REFRESHWINDOW:
  303.       GT_BeginRefresh (FormatterWnd);
  304.       GT_EndRefresh (FormatterWnd, TRUE);
  305.       break;
  306.  
  307.     case IDCMP_VANILLAKEY:
  308.       if ((char) FormatterMsg.Code == ESC)
  309.         running = FALSE;
  310.       break;
  311.  
  312.     case IDCMP_CLOSEWINDOW:
  313.       running = NoFormatGadClicked ();
  314.       break;
  315.  
  316.     case IDCMP_GADGETUP:
  317.       ID = ((GADGET *) FormatterMsg.IAddress)->GadgetID;
  318.  
  319.       HandleHelp ((enum RSysNumbers) ID);
  320.  
  321.       func = (int (*)()) ((GADGET *) FormatterMsg.IAddress)->UserData;
  322.       running = func ();
  323.       break;
  324.     }
  325.     }
  326.  
  327.   return running;
  328. }
  329.  
  330. int
  331. RSysFormatOutput (WINDOW * wind, char *format)
  332. {
  333.   APTR req = NULL;
  334.  
  335.   DPOS;
  336.  
  337.   if (!Flags.textformat)
  338.     {
  339.       strcpy (format, "%s");
  340.       return TFormat.f_noheader;
  341.     }
  342.  
  343.   CopyMem (&TFormatDef, &TFormat, sizeof (RSYS_fmt));
  344.  
  345.   if (OpenASysWindow (OpenFormatterWindow, NO_KILL))
  346.     {
  347.       PrintInfo ("Format output strings", SPEAK, 0);
  348.  
  349.       if (wind)
  350.     req = LockWindow (wind);
  351.  
  352.       while (HandleFormatterIDCMP ());
  353.  
  354.       CloseASysWindow (&FormatterWnd, &FormatterGList, NULL);
  355.  
  356.       if (TFormat.f_noformat == FALSE)
  357.     strcpy (format, TFormat.f_format);
  358.       else
  359.     strcpy (format, "%s");
  360.  
  361.       UnlockWindow (req);
  362.     }
  363.  
  364.   return TFormat.f_noheader;
  365. }
  366.